<template>
  <el-dialog
    v-el-drag-dialog
    title="整改项"
    :visible.sync="visible"
    width="650px"
    @closed="reset"
  >
    <lb-table
      ref="lbTable"
      border
      :column="tableData.column"
      :data="tableData.data"
      :pagination="false"
      :height="300"
      :immediate-fetch="false"
      @fetch="fetchData"
    />
  </el-dialog>
</template>

<script>
  import { gasCheckQueryDetail } from '@/api'

  export default {
    name: 'CheckItem',
    props: {
      warnLevelMap: {
        type: Array,
        required: true
      }
    },
    data() {
      return {
        visible: false,
        tableData: {
          column: [
            {
              type: 'index'
            },
            {
              prop: 'itemName',
              width: 450,
              label: '整改项',
              render: (h, { row }) => <span>{row.itemName}&emsp;&emsp;{row.itemDetailName}</span>
            },
            {
              prop: 'warnLevel',
              label: '隐患级别',
              render: (h, { row }) => <span>{ this.getWarnLevelTip(row.warnLevel, this.warnLevelMap) }</span>
            }
          ],
          data: []
        }
      }
    },
    methods: {
      open(temp) {
        this.fetchData(temp)
        return new Promise(resolve => {
          this.resolve = resolve
          this.visible = true
        })
      },
      async fetchData(temp) {
        const res = await gasCheckQueryDetail({
          checkId: temp.checkId
        })
        this.tableData.data = res.data.billItemList.filter(item => item.warnLevel > 0)
      },
      getWarnLevelTip(warnLevel, warnLevels) {
        if (!warnLevel) return '无隐患'
        const the = warnLevels.find(item => item.keyVal === warnLevel)
        return the ? the.keyName : ''
      },
      reset() {
        this.tableData.data = []
      }
    }
  }
</script>

<style scoped>

</style>
